<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.41">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica; min-height: 22.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
span.s1 {color: #0000bf}
span.s2 {color: #bf0000}
span.s3 {color: #000000}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1">//SLUGens released under the GNU GPL as extensions for SuperCollider 3, by Nick Collins, http://www.informatics.sussex.ac.uk/users/nc81/</p>
<p class="p2"><b></b><br></p>
<p class="p3"><b>VMScan2D<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>2D scanning pattern virtual machine</b></p>
<p class="p2"><b></b><br></p>
<p class="p4"><b>#x,y= VMScan2D.ar(bufnum, fairness, mul, add)</b></p>
<p class="p5"><br></p>
<p class="p4">Converts a buffer of virtual machine instructions into the synthesis of a 2D path.</p>
<p class="p5"><br></p>
<p class="p4"><b>bufnum</b>- Number of buffer holding instructions on the server in the form of successive COMMAND/PARAM PAIRS</p>
<p class="p5"><br></p>
<p class="p4">The limited command set:<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4">0 interpolate from last to new point over PARAM *5000 samples (ie down to about 10 Hz, sampling rate dependent)<span class="Apple-converted-space"> </span></p>
<p class="p4">1 new random point from (PARAM.rand,PARAM.rand)</p>
<p class="p4">2 new point by perturbing last point by PARAM</p>
<p class="p4">3 new point by interpolating from last point to its inversion (x,y) -&gt; (1.0-x, 1.0-y)</p>
<p class="p4">4 new point by interpolating (t=PARAM) last two points</p>
<p class="p4">5 new point by scaling last point (multiply both x and y), scaling= PARAM</p>
<p class="p4">6 new x position for point at PARAM</p>
<p class="p4">7 new y position for point at PARAM</p>
<p class="p4">8 do next command if probability PARAM</p>
<p class="p4">9 goto instruction PARAM within the buffer</p>
<p class="p5"><br></p>
<p class="p4">In most cases, sensible values for PARAM are from 0.0 to 1.0!<span class="Apple-converted-space">  </span>But instruction 9 will need much larger address values.<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4">Scanning paths are generated from successions of straight line segments.<span class="Apple-converted-space"> </span></p>
<p class="p5"><br></p>
<p class="p4"><b>fairness</b>- If 0.0, interpolation is equal in x and y; if 1.0, y just leaps, x even; -1.0 x just leaps, y even</p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p6"><br></p>
<p class="p7"><br></p>
<p class="p1">//Examples</p>
<p class="p7"><br></p>
<p class="p8">(</p>
<p class="p1">//create instruction set; just interpolate (0,0) -&gt; (1,1) -&gt; (0,1) -&gt; (1,0) and loop, with 441 sample interpolation between each point</p>
<p class="p8">c=[6,0,7,0,6,1,7,1,0,0.0882,6,0,7,1,0,0.0882,6,1,7,0,0,0.0882,6,0,7,0,0,0.0882,9,4]++<span class="s1">Array</span>.fill(50,0.0);</p>
<p class="p8">d=<span class="s1">Buffer</span>.sendCollection(s, c, 1);</p>
<p class="p8">)</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p1">//create buffer for wave terrain. I want the equation z = 2*(((x/100)**2) + ((abs(sin(10*y))/50)**(1/3)))-1</p>
<p class="p1">//over a 100 by 50 area</p>
<p class="p7"><br></p>
<p class="p1">//2d to 1d conversion follows index= y*rowlength+ x</p>
<p class="p8">(</p>
<p class="p8"><span class="s1">var</span> width= 100; <span class="s2">//= num cols</span></p>
<p class="p1"><span class="s1">var</span><span class="s3"> height=50; </span>//=num rows, though indexing bottom to top; i.e., standard Cartesian co-ordinates</p>
<p class="p7"><br></p>
<p class="p8">a=<span class="s1">Array</span>.fill(width*height,{<span class="s1">arg</span> i;<span class="Apple-converted-space"> </span></p>
<p class="p8"><span class="s1">var</span> xnow, ynow, x, y;<span class="Apple-converted-space"> </span></p>
<p class="p7"><br></p>
<p class="p8">xnow= i%width;</p>
<p class="p8">ynow= (i-xnow).div(width);</p>
<p class="p7"><br></p>
<p class="p8">x=xnow/width;</p>
<p class="p8">y=ynow/height;</p>
<p class="p7"><br></p>
<p class="p8">2*(((x)**2) + ((abs(sin(10*y)))**(1/3)))-1</p>
<p class="p8">});</p>
<p class="p7"><br></p>
<p class="p8">b=<span class="s1">Buffer</span>.sendCollection(s, a, 1);</p>
<p class="p8">)</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p8">(</p>
<p class="p1">//test scanning virtual machine</p>
<p class="p8">{</p>
<p class="p8"><span class="s1">var</span> scan2d, wt;<span class="Apple-converted-space"> </span></p>
<p class="p7"><br></p>
<p class="p8">scan2d= <span class="s1">VMScan2D</span>.ar(d.bufnum);<span class="Apple-converted-space"> </span></p>
<p class="p7"><br></p>
<p class="p8"><span class="s1">WaveTerrain</span>.ar(b.bufnum,scan2d[0],scan2d[1],100,50)}.play</p>
<p class="p8">)</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p8">(</p>
<p class="p1">//create instruction set; just interpolate (0,0) -&gt; (1,1) -&gt; (0,1) -&gt; (1,0) and loop, with 441 sample interpolation between each point</p>
<p class="p8">c=[6,0,7,0,1,1.0,1,0.5,0,rrand(0.05,0.2),6,1,7,1,0,0.0882,6,0,7,1,8,0.7,0,0.0882,8,0.4,1,0.5,6,1,7,0,0,0.0882,6,0,7,0,0,0.0882,9,4];</p>
<p class="p8">d.sendCollection(c);</p>
<p class="p8">)</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p8">(</p>
<p class="p1">//mouse control of path extent</p>
<p class="p8">{</p>
<p class="p8"><span class="s1">var</span> scan2d, wt;<span class="Apple-converted-space"> </span></p>
<p class="p7"><br></p>
<p class="p8">scan2d= <span class="s1">VMScan2D</span>.ar(d.bufnum);<span class="Apple-converted-space"> </span></p>
<p class="p7"><br></p>
<p class="p8"><span class="s1">WaveTerrain</span>.ar(b.bufnum,scan2d[0]*<span class="s1">MouseX</span>.kr,scan2d[1]*<span class="s1">MouseY</span>.kr,100,50)}.play</p>
<p class="p8">)</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p1">//random instruction sets</p>
<p class="p8">(</p>
<p class="p8">c=<span class="s1">Array</span>.fill(50,{<span class="s1">arg</span> i; if(i.even,{9.rand},{1.0.rand})});</p>
<p class="p1"><span class="s1">Post</span><span class="s3"> &lt;&lt; c &lt;&lt; nl;<span class="Apple-converted-space">  </span></span>//in case you like one</p>
<p class="p8">d.sendCollection(c);</p>
<p class="p8">)</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p8">(</p>
<p class="p8">t=<span class="s1">Task</span>({</p>
<p class="p7"><br></p>
<p class="p8"><span class="s1">inf</span>.do {</p>
<p class="p7"><br></p>
<p class="p8">c=<span class="s1">Array</span>.fill(50,{<span class="s1">arg</span> i; if(i.even,{9.rand},{1.0.rand})});</p>
<p class="p8">d.sendCollection(c);</p>
<p class="p7"><br></p>
<p class="p8">exprand(0.05,1).wait;</p>
<p class="p8">}</p>
<p class="p7"><br></p>
<p class="p8">}</p>
<p class="p8">).play;</p>
<p class="p8">)</p>
<p class="p7"><br></p>
<p class="p8">t.stop;</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p1">//change terrain!<span class="Apple-converted-space"> </span></p>
<p class="p8">(</p>
<p class="p8"><span class="s1">var</span> width= 100; <span class="s2">//= num cols</span></p>
<p class="p1"><span class="s1">var</span><span class="s3"> height=50; </span>//=num rows, though indexing bottom to top; i.e., standard Cartesian co-ordinates</p>
<p class="p7"><br></p>
<p class="p8">a=<span class="s1">Array</span>.fill(width*height,{<span class="s1">arg</span> i;<span class="Apple-converted-space"> </span></p>
<p class="p8"><span class="s1">var</span> xnow, ynow, x, y;<span class="Apple-converted-space"> </span></p>
<p class="p7"><br></p>
<p class="p8">xnow= i%width;</p>
<p class="p8">ynow= (i-xnow).div(width);</p>
<p class="p7"><br></p>
<p class="p8">x=xnow/width;</p>
<p class="p8">y=ynow/height;</p>
<p class="p7"><br></p>
<p class="p8">(((1.3*(cos(rrand(1,2)*x+1.7))**2) - ((abs(sin(rrand(1.2,4.9)*y)))**(1/2)))).max(-1.0).min(1.0)</p>
<p class="p7"><br></p>
<p class="p8">});</p>
<p class="p7"><br></p>
<p class="p8">b.sendCollection(a);</p>
<p class="p8">)</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p1">//more considerate construction of instruction sets</p>
<p class="p8">(</p>
<p class="p8">c= <span class="s1">Array</span>.fill(40,{<span class="s1">arg</span> i; if(i.odd,{if(0.6.coin,{[0,exprand(0.005,0.5)]}, {[8,rrand(0.1,1.0),9,2*rrand(0,15)]})},{if(0.6.coin,{[[1,3,4,5].choose,[exprand(0.1,1.0),rrand(0.1,1.0),exprand(0.01,0.2)].choose]},{[6,1.0.rand,7,1.0.rand]})}); }).flatten.postln;</p>
<p class="p8"><span class="s1">Post</span> &lt;&lt; (c[0..79]) &lt;&lt; nl;</p>
<p class="p8">d.sendCollection(c[0..79]);</p>
<p class="p8">)</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p1">//presets</p>
<p class="p8">(</p>
<p class="p8">c= [ 5, 0.045032007298424, 0, 0.16829266097, 4, 0.21671941633821, 0, 0.097617059383181, 3, 0.039779075792183, 8, 0.60886644124985, 9, 28, 6, 0.6432192325592, 7, 0.42085599899292, 0, 0.49528216896303, 4, 0.99470864534378, 8, 0.84870989322662, 9, 12, 1, 0.47667115650489, 0, 0.49904105498093, 6, 0.78044593334198, 7, 0.5973949432373, 0, 0.0079938346573139, 6, 0.49935853481293, 7, 0.26820993423462, 0, 0.30518372109199, 6, 0.35976254940033, 7, 0.091889262199402, 0, 0.012580000107232, 6, 0.39456367492676, 7, 0.071749925613403, 8, 0.15818494558334, 9, 16, 6, 0.59569001197815, 7, 0.30783140659332, 8, 0.36180495023727, 9, 14, 3, 0.66818692684174, 8, 0.75634309053421, 9, 8, 6, 0.53690254688263, 7, 0.59401845932007, 0, 0.27458241967347, 4, 0.18244198560715, 8, 0.13642364740372, 9, 30, 6, 0.92603194713593, 7, 0.28209984302521, 0, 0.0090666346152647, 6, 0.078964591026306, 7, 0.50376713275909, 0, 0.077060097964172, 1, 0.94782749414444, 0, 0.012215198751997, 5, 0.08951347633044, 0, 0.23426103829321, 5, 0.97009623442827, 8, 0.95121469497681, 9, 12, 6, 0.30078971385956, 7, 0.27361023426056, 8, 0.56096186637878, 9, 16 ];</p>
<p class="p8">d.sendCollection(c[0..79]);</p>
<p class="p8">)</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p1">//aaaaaaaah</p>
<p class="p8">(</p>
<p class="p8">c=[ 1, 0.012401115664331, 0, 0.0085625787306813, 6, 0.92073178291321, 7, 0.92452263832092, 0, 0.0067897107572423, 6, 0.52498006820679, 7, 0.89580702781677, 0, 0.0080293935557327, 1, 0.76127503778645, 8, 0.50952353477478, 9, 4, 1, 0.011272358865916, 8, 0.49296754598618, 9, 30, 5, 0.5126657733169, 8, 0.53715790510178, 9, 2, 5, 0.11751061316084, 0, 0.027315109664648, 6, 0.23468768596649, 7, 0.71995985507965, 0, 0.20785921190348, 6, 0.80761659145355, 7, 0.14734661579132, 0, 0.21667175878798, 6, 0.82812416553497, 7, 0.555588722229, 0, 0.26813978221146, 6, 0.62556290626526, 7, 0.89661765098572, 0, 0.0085612522419438, 6, 0.77029120922089, 7, 0.77577233314514, 0, 0.035287317732313, 5, 0.58347815275192, 0, 0.17061046232705, 6, 0.30991017818451, 7, 0.89471626281738, 8, 0.29139889478683, 9, 12 ];</p>
<p class="p8">d.sendCollection(c);</p>
<p class="p8">)</p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p7"><br></p>
<p class="p1">//rrrar</p>
<p class="p8">(</p>
<p class="p8">c=[ 6, 0.62479221820831, 7, 0.84334719181061, 0, 0.12737253976876, 1, 0.34590717554092, 8, 0.90837938785553, 9, 14, 3, 0.64444444179535, 0, 0.0076382220180926, 6, 0.21171295642853, 7, 0.061154127120972, 0, 0.087469286732226, 5, 0.90200103839312, 8, 0.80244028568268, 9, 20, 4, 0.13062523433243, 0, 0.040084850746492, 1, 0.3471907625919, 0, 0.2711738771992, 5, 0.051819064032369, 0, 0.3250898321643, 4, 0.6964198589325, 8, 0.80261430740356, 9, 0, 1, 0.18071593046188, 8, 0.77187951803207, 9, 0, 1, 0.38054929971695, 8, 0.10199545621872, 9, 6, 5, 0.1556055188179, 0, 0.0079423607059602, 1, 0.16413666490274, 0, 0.015987433587358, 6, 0.89596319198608, 7, 0.27058398723602, 0, 0.096067733476108, 6, 0.81998920440674, 7, 0.4519407749176, 0, 0.35322635035146, 4, 0.025783616661822 ];</p>
<p class="p8">d.sendCollection(c);</p>
<p class="p8">)</p>
<p class="p7"><br></p>
<p class="p1">//additional ideas: polar co-ordinates, scanning paths on circle boundaries connecting two last points?<span class="Apple-converted-space"> </span></p>
</body>
</html>
